package com.learning.thread.juc.executor.defined;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * ClassName: CustomThreadPoolExecutor
 * Description: 自定义线程池扩展
 * 所有的线程池都使用 ThreadPoolExecutor 这个类
 * 可以重载方法beforeExecute 和 afterExecute
 * Date: 2016/11/26 17:45
 *
 * @author SAM SHO
 * @version V1.0
 */
public class CustomExpandThreadPoolExecutor extends ThreadPoolExecutor {

    public CustomExpandThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
    }

    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        System.out.println("线程执行开始前" + t.getId() + "_" + t.getName() + "_" + ((CustomTaskThread) r).getName());
    }

    @Override
    protected void afterExecute(Runnable r, Throwable t) {
        System.out.println("线程执行结束后 " + Thread.currentThread().getName());
        System.out.println("结束后 PoolSize " + this.getPoolSize());
    }


}
